SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd)
ark_root=$(dirname $(dirname $(dirname $(dirname "$SCRIPT_DIR"))))
arkcompiler_tool_path=$(dirname "$ark_root")/arkcompiler_tool
ark_guard_root=$ark_root/arkcompiler/runtime_core/ark_guard
abckit_wrapper_root=$ark_guard_root/abckit_wrapper
arktsconfig_template=$abckit_wrapper_root/script/arktsconfig.json
src_root=$ark_guard_root/tests/ut
build_root=$ark_guard_root/tests/build/ut
arktsconfig_file=$ark_guard_root/tests/build/ut/arktsconfig.json

# Modify the following configuration according to the abc to be compiled
obfuscated_file_name=enum_demo
obfuscated_file_path=$ark_guard_root/tests/ut/obfuscator/code_sample
obfuscated_file_out_path=$ark_guard_root/tests/build/ut/obfuscator/code_sample

# Don't modify the following code
input_ets=$obfuscated_file_path/$obfuscated_file_name.ets
out_abc=$obfuscated_file_out_path/$obfuscated_file_name.abc
out_abc_pa=$obfuscated_file_out_path/$obfuscated_file_name.pa

if [ ! -d "$obfuscated_file_out_path" ]; then
    mkdir -p "$obfuscated_file_out_path" || { echo "Failed to create directory"; exit 1; }
fi

python $abckit_wrapper_root/script/gen_arktsconfig.py --arkcompiler_tool_path $arkcompiler_tool_path --arktsconfig_template $arktsconfig_template --src_root $src_root --build_root $build_root

export LD_LIBRARY_PATH=$arkcompiler_tool_path/clang_x64
$arkcompiler_tool_path/clang_x64/es2panda --opt-level=0 --arktsconfig /$arktsconfig_file --output $out_abc $input_ets
$arkcompiler_tool_path/clang_x64/ark_disasm_static $out_abc $out_abc_pa
